package com.example.wac.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wac.entity.LoginUser;
import com.example.wac.entity.system.LoginInfo;
import com.example.wac.enums.ErrorCode;
import com.example.wac.mapper.LoginUserMapper;
import com.example.wac.service.LoginUserService;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * <p>
 * 登录用户表 服务实现类
 * </p>
 *
 * @author wac
 * @since 2022-04-24
 */
@Service
public class LoginUserServiceImpl extends ServiceImpl<LoginUserMapper, LoginInfo> implements LoginUserService {

    @Override
    public LoginInfo findUserByLoginName(String loginName) {
        try {
            LoginInfo user = new LambdaQueryChainWrapper<>(this.baseMapper)
                    .eq(LoginInfo::getMobile, loginName)
                    .eq(LoginInfo::getState, 0)
                    .one();
            return user;
        }catch (Exception e){
            throw ErrorCode.HAVE_NON_UNIQUE_NAME.getAppException();
        }
    }


    @Override
    public LoginInfo getLoginInfoByMobile(String mobile) {
        return getBaseMapper().getLoginInfoByMobile(mobile);
    }

    @Override
    public Set<String> selectPermsByMobile(String mobile) {
        return getBaseMapper().selectPermsByMobile(mobile);
    }

    @Override
    public Set<String> selectRoleCodeByMobile(String mobile) {
        return getBaseMapper().selectRoleCodeByMobile(mobile);
    }
}
